import React, { Component } from 'react'
import ReactDom from 'react-dom'
export default class Index extends Component {
    state = {
        isShowButton : true
    }

    txtRef = React.createRef()

    hClick = () => {
        this.setState({isShowButton: false} ,() => {
            this.txtRef.current.focus()
        })
    }
    render() {
        return (
            <div style={{padding:50}}>
                {
                    this.state.isShowButton ? 
                    <button onClick={this.hClick}>添加</button> :

                    <input type="text" ref={this.txtRef}/>

                }
            </div>
        )
    }
}
ReactDom.render(<Index></Index>, document.getElementById('root'))

